/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.thienloc.omap.session;

import com.thienloc.omap.entity.OmapRole;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import org.slf4j.LoggerFactory;

/**
 *
 * @author GiangLT
 */
@Stateless
public class OmapRoleFacade extends AbstractFacade<OmapRole> {

    @PersistenceContext(unitName = "omapPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public OmapRoleFacade() {
        super(OmapRole.class);
    }

    public OmapRole findByRoleName(String roleName) {
        try {
            TypedQuery<OmapRole> q = em.createNamedQuery("OmapRole.findByRoleName", OmapRole.class);
            q.setParameter("roleName", roleName);
            return q.getSingleResult();

        } catch (NoResultException ex) {
            return null;
        } catch (Exception ex) {
            LoggerFactory.getLogger(OmapRoleFacade.class.getName()).error("", ex);
            return null;
        }
    }
}
